package com.ssd.controller.operation;

import com.github.pagehelper.PageInfo;
import com.ssd.entity.operation.dto.AssginRoleDto;
import com.ssd.entity.operation.dto.SysUserDto;
import com.ssd.entity.operation.entity.SysUser;
import com.ssd.service.SysUserService;
import com.ssd.view.BaseResponse;
import com.ssd.viewmodel.Pager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 系统用户表 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/admin/user")
@Api(tags = "系统用户表 前端控制器")
public class SysUserController {
    @Resource
    private SysUserService userService;
    //1 用户条件分页查询接口
    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
    @ApiOperation(value = "用户条件分页查询接口")
    public BaseResponse<Pager<SysUser>> findByPage(@PathVariable("pageNum") Integer pageNum,
                                          @PathVariable("pageSize") Integer pageSize,
                                          SysUserDto sysUserDto) {
        PageInfo<SysUser> pageInfo = userService.findByPage(pageNum,pageSize,sysUserDto);
        return new BaseResponse(pageInfo);
    }

    //2 用户添加
    @PostMapping("/saveSysUser")
    @ApiOperation(value = "用户添加")
    public BaseResponse saveSysUser(@RequestBody SysUser sysUser) {
        userService.saveSysUser(sysUser);
        return new BaseResponse();
    }

    //3 用户修改
    @PutMapping("/updateSysUser")
    @ApiOperation(value = "用户修改")
    public BaseResponse updateSysUser(@RequestBody SysUser sysUser) {
        userService.updateSysUser(sysUser);
        return new BaseResponse();
    }

    //4 用户删除
    @DeleteMapping("/deleteById/{userId}")
    @ApiOperation(value = "用户删除")
    public BaseResponse deleteById(@PathVariable("userId") Long userId) {
        userService.deleteById(userId);
        return new BaseResponse();
    }

    //用户分配角色
    //保存分配数据
    @PostMapping("/doAssign")
    @ApiOperation(value = "用户分配角色")
    public BaseResponse doAssign(@RequestBody AssginRoleDto assginRoleDto) {
        userService.doAssign(assginRoleDto);
        return new BaseResponse();
    }

}
